import * as types from '../types';
import * as utils from '../../utils/helps';
import api from 'api';
import chart from './chart';

const app = {
  state: {
    // 应用信息,{name:XXX,id:XXX}
    appData: JSON.parse(localStorage.getItem('appData') || '{}'),
    // 应用保存状态
    isAppSave: true,
    // 外观(布局设置+背景)
    appearance: {},
    // 组件们，存储id
    componentsId: [],
    // 联动字段
    interactionParams: {},
    // 全局过滤条件
    globalFilter: '',
  },
  getters: {},
  mutations: {
    // 更新浏览的应用信息
    [types.UPDATA_APP_DATA](state, data) {
      state.appData = {
        id: data.id,
        name: data.name,
      };
      localStorage.setItem('appData', JSON.stringify(data));
      state.allControl = {};
      state.currentId = '';
    },
    // 应用保存状态
    [types.UPDATE_APP_STATE](state) {
      state.isAppSave = !state.isAppSave;
    },
    // 存储组件id   appList(Array)
    [types.UPDATA_APP_COMPONENTS](state, { ids, firstUpdate }) {
      if (firstUpdate) {
        state.componentsId = [];
        state.componentsId = ids;
      } else {
        state.componentsId.push(ids);
      }
    },
  },
  actions: {},
};

export default app;
